package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.purchaseindexrecord.LindiPurchaseIndexRecordQueryVO;
import com.minimalist.common.entity.lindi.vo.purchaseindexrecord.LindiPurchaseIndexRecordVO;
import com.minimalist.common.feign.client.lindi.LindiPurchaseIndexRecordFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 林地指标交易平台_购买指标记录控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_购买指标记录管理")
@RequestMapping("/basic/lindi/purchaseIndexRecord")
public class LindiPurchaseIndexRecordController{

    @Autowired
    private LindiPurchaseIndexRecordFeignClient feignClient;

    @PostMapping("/addPurchaseIndexRecord")
    @Operation(summary = "添加购买指标记录")
    @SaCheckPermission("lindi:purchaseIndexRecord:add")
    public R<?> addPurchaseIndexRecord(
            @RequestBody @Validated(Add.class) LindiPurchaseIndexRecordVO
                    purchaseIndexRecordVO){
        purchaseIndexRecordVO.setCreateId(StpUtil.getLoginIdAsLong());
        purchaseIndexRecordVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        purchaseIndexRecordVO.setCreateTime(now);
        purchaseIndexRecordVO.setUpdateTime(now);
        return feignClient.addPurchaseIndexRecord(purchaseIndexRecordVO);
    }

    @DeleteMapping("/deletePurchaseIndexRecordByPurchaseIndexRecordId")
    @Operation(summary = "删除购买指标记录 -> 根据购买指标记录ID删除")
    @SaCheckPermission("lindi:purchaseIndexRecord:delete")
    public R<?> deletePurchaseIndexRecordByPurchaseIndexRecordId(
            @RequestParam("purchaseIndexRecordId")
            @NotNull(message = "购买指标记录ID不能为空")
            @Parameter(name = "purchaseIndexRecordId", required = true, description = "购买指标记录ID")
            Long purchaseIndexRecordId){
        return feignClient.deletePurchaseIndexRecordByPurchaseIndexRecordId(
                purchaseIndexRecordId);
    }

    @PutMapping("/updatePurchaseIndexRecordByPurchaseIndexRecordId")
    @Operation(summary = "修改购买指标记录")
    @SaCheckPermission("lindi:purchaseIndexRecord:update")
    public R<?> updatePurchaseIndexRecordByPurchaseIndexRecordId(
            @RequestBody @Validated(Update.class) LindiPurchaseIndexRecordVO
                    purchaseIndexRecordVO){
        purchaseIndexRecordVO.setCreateId(StpUtil.getLoginIdAsLong());
        purchaseIndexRecordVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        purchaseIndexRecordVO.setCreateTime(now);
        purchaseIndexRecordVO.setUpdateTime(now);
        return feignClient.updatePurchaseIndexRecordByPurchaseIndexRecordId(purchaseIndexRecordVO);
    }

    @GetMapping("/getPagePurchaseIndexRecordList")
    @Operation(summary = "查询购买指标记录列表(分页)")
    @SaCheckPermission("lindi:purchaseIndexRecord:get")
    public R<PageResp<LindiPurchaseIndexRecordVO>> getPagePurchaseIndexRecordList(
            LindiPurchaseIndexRecordQueryVO queryVO){
        return feignClient.getPagePurchaseIndexRecordList(queryVO);
    }

    @GetMapping("/getPurchaseIndexRecordByPurchaseIndexRecordId/{purchaseIndexRecordId}")
    @Operation(summary = "根据购买指标记录ID查询购买指标记录")
    @SaCheckPermission("lindi:purchaseIndexRecord:get")
    public R<LindiPurchaseIndexRecordVO> getPurchaseIndexRecordByPurchaseIndexRecordId(
            @PathVariable(value = "purchaseIndexRecordId")
            @NotNull(message = "购买指标记录ID不能为空")
            @Parameter(name = "purchaseIndexRecordId", description = "购买指标记录ID", required = true)
            Long purchaseIndexRecordId){
        return feignClient.getPurchaseIndexRecordByPurchaseIndexRecordId(purchaseIndexRecordId);
    }
    
    @PostMapping("/deletePurchaseIndexRecordFileByFileId")
    @Operation(summary = "删除购买指标记录文件 -> 根据文件ID删除")
    @SaCheckPermission("lindi:purchaseIndexRecord:update")
    public R<?> deletePurchaseIndexRecordFileByFileId(
            @RequestParam("fileId")
            @NotNull(message = "文件ID不能为空")
            @Parameter(name = "fileId", description = "文件ID", required = true)
            Long fileId){
        return feignClient.deletePurchaseIndexRecordFileByFileId(fileId);
    }
}
